package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Filter {

    List<Integer>  array;

    public Filter(List<Integer> array) {
        this.array = array;
    }

    public List<Integer> filterEven() {
        List<Integer> list = new ArrayList<>();
        for (Integer integer : array) {
            if (integer % 2 == 0){
                list.add(integer);
            }
        }
        return list;
    }

    public List<Integer> filterMultipleOfThree() {
        List<Integer> list = new ArrayList<>();
        for (Integer integer : array) {
            if (integer % 3 == 0){
                list.add(integer);
            }
        }
        return list;
    }
    public List<Integer> getDifferentElements() {
        List<Integer> list = new ArrayList<>();
        HashSet set = new HashSet();
        set.addAll(array);
        list.addAll(set);
        return list;
//        return array.stream().distinct().collect(Collectors.toList());
    }
    public List<Integer> getCommonElements(List<Integer> firstList, List<Integer> secondList) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < firstList.size(); i++) {
            for (int j = 0; j < secondList.size(); j++) {
                if (firstList.get(i) == secondList.get(j)){

                    list.add(firstList.get(i));
                }
            }
        }
        return list;
//        return firstList.stream().filter(secondList::contains).collect(Collectors.toList());
    }


}